#include<stdio.h>
#include<stdlib.h>
#include "QStack.h"

int checkMatch(char a , char b){
	if( (a == '[' && b == ']') || ( a == '(' && b == ')' ) ){
		return 1;
	}else
		return 0;
}

int isBracket( char a ){
	if( a == '[' || a == '(' )
		return 2;
	else if( a == ']' || a == ')' )
		return 1;
	else 
		return 0;
}

int bracketMatch( char *s ){
	char *p = s;
	char t;
	QStype *qs = (QStype*) malloc ( sizeof( QStype ) );
	initiateQStack(qs);

	while(*p != '\0'){
		if( isBracket( *p )  == 2 ){
			pushQStack( qs, *p );
		}else if( isBracket( *p ) == 1 ){
			if( isEmpty( qs ) )
				return 0;
			if( !checkMatch( getTopElem( qs ), *p ) )
				return 0;
			else{
				if( !popQStack( qs, &t ) )
					return 0;
			}
		}
		p++;
	}
	if( !isEmpty( qs ) )
		return 0;
	return 1;
}
int main(  ){
	char *a = ( char * ) malloc (  100 * sizeof( char ) );
	scanf( "%s", a );
	if(bracketMatch( a ))
		printf( "matched" );
	else
		printf( "not matched" );
}
